<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form :form="form" slot="detail">
        <a-row>
           <a-col :span="24">
            <a-form-item label="作业队伍类别" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="list" v-decorator="['teamType',validatorRules.teamType]" :trigger-change="true" dictCode="team_type" placeholder="请选择作业队伍类别"/>
            </a-form-item>
          </a-col>
           <a-col :span="24">
            <a-form-item label="有限空间类别" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="list" v-decorator="['limitSpaceType',validatorRules.limitSpaceType]" :trigger-change="true" dictCode="limit_space_type" placeholder="请选择有限空间类别"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="工作协调人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['workConcertPerson',validatorRules.workConcertPerson]" placeholder="请输入工作协调人"></a-input>
            </a-form-item>
          </a-col>
           <a-col :span="24">
            <a-form-item label="第二监护人所在班组" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['concertClass2',validatorRules.concertClass2]" placeholder="请输入第二监护人所在班组"></a-input>
            </a-form-item>
          </a-col>
           <a-col :span="24">
            <a-form-item label="工作负责人(监护人)" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['workOndutyPerson',validatorRules.workOndutyPerson]" placeholder="请输入工作负责人(监护人)"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="工作班成员" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['classMember',validatorRules.classMember]" placeholder="请输入工作班成员"></a-input>
            </a-form-item>
          </a-col>
           <a-col :span="24">
            <a-form-item label="工作任务" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['workTask',validatorRules.workTask]" placeholder="请输入工作任务"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="工作内容" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-textarea
                v-decorator="['workDetail',validatorRules.workDetail]"
                placeholder="请输入工作内容"
                :auto-size="{ minRows: 3, maxRows: 5 }"
              />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="安全措施(负责人填写)" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-textarea
                v-decorator="['safeAction',validatorRules.safeAction]"
                placeholder="请输入安全措施(负责人填写)"
                :auto-size="{ minRows: 3, maxRows: 5 }"
              />
            </a-form-item>
          </a-col>
           <a-col :span="24">
            <a-form-item label="执行情况(工作许可人填写)" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-textarea
                v-decorator="['actionDetail',validatorRules.actionDetail]"
                placeholder="请输入执行情况(工作许可人填写)"
                :auto-size="{ minRows: 3, maxRows: 5 }"
              />
            </a-form-item>
          </a-col>
           <a-col :span="24">
            <a-form-item label="工作许可人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['workPermmitPerson',validatorRules.workPermmitPerson]" placeholder="请输入工作许可人"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="值班负责人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['onDutyPerson',validatorRules.onDutyPerson]" placeholder="请输入值班负责人"></a-input>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JFormContainer from '@/components/jeecg/JFormContainer'
  import JDate from '@/components/jeecg/JDate'  
  import JSelectDepart from '@/components/jeecgbiz/JSelectDepart'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"

  export default {
    name: 'OneElectricalForm',
    components: {
      JFormContainer,
      JDate,
      JSelectDepart,
      JDictSelectTag,
    },
    props: {
      //流程表单data
      formData: {
        type: Object,
        default: ()=>{},
        required: false
      },
      //表单模式：true流程表单 false普通表单
      formBpm: {
        type: Boolean,
        default: false,
        required: false
      },
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          teamType: {
            rules: [
              { required: true, message: '请输入作业队伍类别!'},
            ]
          },
          limitSpaceType: {
            rules: [
              { required: true, message: '请输入有限空间类别!'},
            ]
          },
          workConcertPerson: {
            rules: [
              { required: true, message: '请输入工作协调人!'},
            ]
          },
          concertClass2: {
            rules: [
              { required: true, message: '请输入第二监护人所在班组!'},
            ]
          },
          workOndutyPerson: {
            rules: [
              { required: true, message: '请输入工作负责人!'},
            ]
          },
           classMember: {
            rules: [
              { required: true, message: '请输入工作班成员!'},
            ]
          },
           workTask: {
            rules: [
              { required: true, message: '请输入工作任务!'},
            ]
          },
           workDetail: {
            rules: [
              { required: true, message: '请输入工作内容!'},
            ]
          },
           safeAction: {
            rules: [
              { required: true, message: '请输入安全措施!'},
            ]
          },
           actionDetail: {
            rules: [
              { required: true, message: '请输入执行情况!'},
            ]
          },
           workPermmitPerson: {
            rules: [
              { required: true, message: '请输入工作许可人!'},
            ]
          },
           onDutyPerson: {
            rules: [
              { required: true, message: '请输入值班负责人!'},
            ]
          },
           
        },
        url: {
          add: "/one_electrical/oneElectrical/add",
          edit: "/one_electrical/oneElectrical/edit",
          queryById: "/one_electrical/oneElectrical/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return false
          }
          return true
        }
        return this.disabled
      },
      showFlowSubmitButton(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return true
          }
        }
        return false
      }
    },
    created () {
      //如果是流程中表单，则需要加载流程表单data
      this.showFlowData();
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'num','redNum','teamType','workConcertPerson','concertClass1','concertClass2','limitSpaceType','opageNum','classMember','workTask','workDetail','planStartDate','planEndDate','safeAction','actionDetail','workPermmitPerson','onDutyPerson','ticketAssignDate','ticketAssignSign','ticketAcceptDate','ticketAcceptSign','orgName','runPermmitDate','workPermmitSign','checkPermmitDate','workOndutySign','workOndutyPerson','oldOndutyPerson','newOndutyPerson','asOkDate','psOkDate','ticketAssignSign2','workPermmitSign2','classLeaveList','classIntoList','workOndutySign2','studySignList','ticketLayoutDate','layoutApplyDate','layoutPermmitDate','ticketOverDate','workOndutySign3','workPermmitSign3','testPermmitDate1','testPermmitDate2','testPermmitDate3','workPermmitPerson1','workPermmitPerson2','workPermmitPerson3','reworkPermmitDate1','reworkPermmitDate2','reworkPermmitDate3','workPermmitPerson4','workPermmitPerson5','workPermmitPerson6','workOndutyPerson1','workOndutyPerson2','workOndutyPerson3','workOndutyPerson4','workOndutyPerson5','workOndutyPerson6','noTestReason','allWire','openWire','closeWire','wireId','ondutyPersonSign','ondutyClass','secondConcertClass'))
        })
      },
      //渲染流程表单数据
      showFlowData(){
        if(this.formBpm === true){
          let params = {id:this.formData.dataId};
          getAction(this.url.queryById,params).then((res)=>{
            if(res.success){
              this.edit (res.result);
            }
          });
        }
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'num','redNum','teamType','workConcertPerson','concertClass1','concertClass2','limitSpaceType','opageNum','classMember','workTask','workDetail','planStartDate','planEndDate','safeAction','actionDetail','workPermmitPerson','onDutyPerson','ticketAssignDate','ticketAssignSign','ticketAcceptDate','ticketAcceptSign','orgName','runPermmitDate','workPermmitSign','checkPermmitDate','workOndutySign','workOndutyPerson','oldOndutyPerson','newOndutyPerson','asOkDate','psOkDate','ticketAssignSign2','workPermmitSign2','classLeaveList','classIntoList','workOndutySign2','studySignList','ticketLayoutDate','layoutApplyDate','layoutPermmitDate','ticketOverDate','workOndutySign3','workPermmitSign3','testPermmitDate1','testPermmitDate2','testPermmitDate3','workPermmitPerson1','workPermmitPerson2','workPermmitPerson3','reworkPermmitDate1','reworkPermmitDate2','reworkPermmitDate3','workPermmitPerson4','workPermmitPerson5','workPermmitPerson6','workOndutyPerson1','workOndutyPerson2','workOndutyPerson3','workOndutyPerson4','workOndutyPerson5','workOndutyPerson6','noTestReason','allWire','openWire','closeWire','wireId','ondutyPersonSign','ondutyClass','secondConcertClass'))
      },
    }
  }
</script>